using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace Kevin.Framework.Data.Query
{
    public sealed class QueryColumn : ExpressionClip
    {
        public static QueryColumn All()
        {
            return new QueryColumn("*", DbType.Int32);
        }

        public static QueryColumn All(IQueryTable table)
        {
            if (table == null)
                return new QueryColumn("*", DbType.Int32);

            return new QueryColumn(string.Format("[{0}].*", table.___GetTableName()), DbType.Int32);
        }

        

        public string Name
        {
            get
            {
                return this.ToString().Replace("[", string.Empty).Replace("]", string.Empty);
            }
        }

        public OrderByClip Desc
        {
            get
            {
                return new OrderByClip(this, true);
            }
        }

        public OrderByClip Asc
        {
            get
            {
                return new OrderByClip(this, false);
            }
        }

        public QueryColumn(string name, DbType type)
        {
           //Check.Require(!string.IsNullOrEmpty(name), "name could not be null or empty.");

            SqlQueryUtils.AppendColumnName(this.sql, name);
            this.DbType = type;
        }

        public QueryColumn(OrmMapping.ORMMappingItem item)
        {
            SqlQueryUtils.AppendColumnName(this.sql, item.DataFieldName);
            this.DbType = item.Db_Type;
        }
    }
}
